package com.smasher.bluetooth.fragment;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.smasher.bluetooth.R;
import com.smasher.decoration.group.GroupSwordDelegate;
import com.smasher.widget.base.BaseRecyclerAdapter;

public class DeviceAdapter extends BaseRecyclerAdapter<BluetoothDevice, DeviceViewHolder> implements GroupSwordDelegate {

    private int pairedCount = 0;

    @Override
    public DeviceViewHolder onCreateDefineViewHolder(@NonNull ViewGroup viewGroup, int i) {
        Context context = viewGroup.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_device, viewGroup, false);
        return new DeviceViewHolder(view);
    }

    public void setPairedCount(int count) {
        pairedCount = count;
    }

    @NonNull
    @Override
    public String getGroupName(int position) {
        if (position < pairedCount) {
            return "已配对设备";
        } else {
            return "其它设备";
        }
    }

    @Override
    public boolean isGroupHeader(int position) {
        return position == 0 || position == pairedCount;
    }
}
